<template>
	<view class="cart-container" v-if="cart.length !== 0">
		<!-- 收货地址组件 -->
		<my-address></my-address>
		
		
		<!-- 商品列表的标题区域 -->
		<view class="cart-title">
			<!-- 左侧的图标 -->
			<uni-icons type="cart-filled" size="18"></uni-icons>
			<!-- 右侧的文本 -->
			<text class="cart-title-text">购物车</text>
		</view>
		
	
		<uni-swipe-action>
			<!-- 循环渲染购物车中的商品数据 -->
			<block v-for="(item,index) in cart" :key="index">
			<uni-swipe-action-item :options="options" @click="swipeItemClickHandler(item)">
				<my-goods :goods="item" :show-radio="true" @radio-change="radioChangeHandler" :show-num="true" @num-change="numberChangeHandler"></my-goods>
			</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		
		
		<!-- 使用的自定义的结算组件 -->
		<my-settle></my-settle>
	</view>
	
	<!-- 空白购物车的区域 -->
	<view class="empey-cart" v-else>
		<image src="" mode="" class="empty-image"></image>
		<text class="tip-text">空空如也~</text>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	import {mapState,mapMutations} from 'vuex'
	
	export default {
		computed:{
			...mapState('my_cart',['cart'])
		},
		mixins:['badgeMix'],
		
		data() {
			return {
				options:{
					text:'删除',
					style:{
						backgroundColor:'#C00000'
					}
				}
			};
		},
		methods:{
			...mapMutations('my_cart',['updateGoodsState','updateGoodsCount','removeGoodsById']),
			
			radioChangeHandler(e){
				// e是商品的数据
				console.log(e)
				this.updateGoodsState(e)
			},
			
			numberChangeHandler(e){
				console.log(e)
				this.updateGoodsCount(e)
			},
			
			swipeItemClickHandler(goods){
				console.log(goods)
				this.removeGoodsById(goods.goods_id)
			}
		}
	}
</script>

<style lang="scss">
	// 我就不写css
	// 空白购物车的区域css
</style>
